package com.jianghu;

import com.jianghu.helpers.ExitProcess;
import com.jianghu.helpers.LoginStatus;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class JiangHu extends Activity {

	private SharedPreferences sp;
	private String password = "password";
	private String username = "username";

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		sp = getSharedPreferences("UserInfo", 0);
		//sp.edit().putString("password", "").commit();// Just for test
		username = sp.getString(username, "");
		password = sp.getString(password, "");

		if (password != "") {
			if (LoginStatus.gotologin(username, password)) {
				Intent intent = new Intent();
				intent.setClass(JiangHu.this, MainPage.class);
				JiangHu.this.startActivity(intent);
			} else {

				Intent intent = new Intent();
				intent.setClass(JiangHu.this, LoginPage.class);
				JiangHu.this.startActivity(intent);
			}

		} else {
			Intent intent = new Intent();
			intent.setClass(JiangHu.this, LoginPage.class);
			JiangHu.this.startActivity(intent);
		}

	}

	@Override
	protected void onStart() {
		int flag = getIntent().getIntExtra("flag", 0);
		if (flag == ExitProcess.EXIT_APPLICATION) {
			finish();
		}
		super.onResume();
	}

	@Override
	protected void onNewIntent(Intent intent) {
		int flag = getIntent().getIntExtra("flag", 0);
		if (flag == ExitProcess.EXIT_APPLICATION) {
			finish();
		}
		super.onNewIntent(intent);
	}
}